package network;

import thread.Demo;

class ListNode {
      int val;
      ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

public class demo {


    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head.next;
        ListNode preCur = head;
        int num = head.val;
        while(cur.next != null) {
            if(cur.val == num) {
               cur = cur.next;
            } else {
                preCur.next = cur;
                preCur = preCur.next;
                num = preCur.val;
            }
        }

        if (cur.val == preCur.val) {
            preCur.next = cur.next;
        } else {
            preCur.next = cur;
        }



//        if(cur.val == num) {
//            System.out.println(num);
//            preCur.next = cur.next;
//        }

        return head;
    }

    public void display(ListNode head) {
        ListNode cur = head;
        while (cur != null) {
            System.out.print(cur.val + "  ");
            cur = cur.next;
        }
    }

    public static void main(String[] args) {
        ListNode a = new ListNode(1,null);
        ListNode b = new ListNode(1,null);
        ListNode c = new ListNode(2,null);
//        ListNode d = new ListNode(3,null);
//        ListNode f = new ListNode(3,null);
        a.next = b;
        b.next = c;
//        c.next = d;
//        d.next = f;
        demo demo = new demo();
        demo.deleteDuplicates(a);
        demo.display(a);
        //System.out.println("--------");

    }
}
